/**
* @CopyRight tstudy.com.cn
* @author wuyahui
* @E-mail wuyahui0124505@163.com
* @version 1.0.0
* @Date  2015年4月3日 下午1:03:40
*/
package com.tstudy.laoshibang.active;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.StringRes;

import com.tstudy.laoshibang.R;
import com.tstudy.laoshibang.base.BaseActivity;
import com.tstudy.laoshibang.base.BaseApplication;
import com.tstudy.laoshibang.base.BaseFragment;
import com.tstudy.laoshibang.base.CONSTANT;
import com.tstudy.laoshibang.utils.LogUtil;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
@EFragment(R.layout.apply_result)
public class ApplyResultFragment extends BaseFragment{
	final static String TAG = "apply_result";
	public ApplyResultFragment() {
		super();
	}
	
	@ViewById(R.id.apply_result_root)
	RelativeLayout mRootLayout;
	
	@ViewById(R.id.apply_result_tip)
	TextView mActiveResult;
	
	boolean mIsFirstLoad = true;
	Handler mHandler;
	LayoutInflater mInflater;
	
	public String mResult;
	int mCurrentPosition = 0;
	@StringRes(R.string.select_all)
	String mSelectAllStr;
	int mSelectAllKey = -1;

	public static void add(int containerViewId,String result) {
		Bundle args = new Bundle();
		args.putInt(CONSTANT.ARGS.FRAGMENT_ID, containerViewId);
		args.putString(CONSTANT.ARGS.APPLY_RESULT, result);
		Fragment fragment = Fragment.instantiate(BaseApplication.mContext,ApplyResultFragment_.class.getName(),args);
		((BaseActivity) BaseApplication.mCurrentActivity).add(containerViewId, fragment, TAG);
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		mHandler = new Handler();
		super.onCreate(savedInstanceState);
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mInflater = inflater;
		super.onCreateView(inflater, container, savedInstanceState);
		LogUtil.d("--mBaseLayout==" + mRootLayout);
		mIsFirstLoad = mRootLayout == null;
		if (mRootLayout != null) {
			((ViewGroup) mRootLayout.getParent()).removeAllViews();
		}
		return mRootLayout;
	}
	
	@AfterViews
	public void initView(){
		if (mIsFirstLoad) {
			mActiveResult.setText(mResult);
		}
	}
	@Click({R.id.apply_result_back,R.id.apply_result_more,R.id.apply_result_more_active})
	public void actionClick(View view){
		switch (view.getId()) {
		case R.id.apply_result_back:
			backAction(mFragmentId);
			break;
		case R.id.apply_result_more:
			backAction(mFragmentId);
			backAction(mFragmentId);
			break;
		case R.id.apply_result_more_active:
			backAction(mFragmentId);
			backAction(mFragmentId);
			backAction(mFragmentId);
			break;
		default:
			break;
		}
	}
	
	@Override
	public void clear() {
		// TODO Auto-generated method stub
	}

	@Override
	public void initArgs(Bundle args) {
		if (args != null) {
			mFragmentId = args.getInt(CONSTANT.ARGS.FRAGMENT_ID);
			mResult = args.getString(CONSTANT.ARGS.APPLY_RESULT);
		}
	}

}
